import requests
from bs4 import BeautifulSoup
from fake_useragent import UserAgent

ua = UserAgent()

shop = {"lenta" : "lenta_vpmtc"} #,        "magnit" : "magnit_sazonova_33"

headers = {"User-Agent" : ua.random}


def get_list_url(shop:dict):
    url_list = []
    for values, key in shop.items():
        url = f"https://eda.yandex.ru/retail/omsk/{values}?placeSlug={key}"
        responce = requests.get(url=url, timeout=30, headers=headers).text
        print(headers)
        soup = BeautifulSoup(responce, "html.parser")
        catalog = soup.find("div", class_="UiKitShopMenu_root")
        catalog_list = catalog.find_all("a", class_="UiKitDesktopShopMenuItem_menuLink")
        url_list = []
        for row in catalog_list:
            url_catalog = f"https://eda.yandex.ru/{row['href']}"
            url_list.append(url_catalog)

    return url_list


for url in get_list_url(shop=shop):
    print(url)
    responce = requests.get(url=url, timeout=30, headers=headers).text
    soup = BeautifulSoup(responce, "html.parser")
    categories = soup.find_all("div", class_="DesktopGoodsList_root")
    for row in categories:
        # categories_title = row.find("div", class_="UiKitCategoryHeader_root").text.strip()
        price = row.find_all("li", class_="DesktopGoodsList_item")
        for card in price:
            card_url = f"https://eda.yandex.ru/{card.find('a', class_='GoodsCard_root GoodsCard_m GoodsCard_clickable')['href']}"
            # card_structure = card.find("a", class_="GoodsCard_root GoodsCard_m GoodsCard_clickable")["description"]
            card_price = card.find("div", class_="UiKitPrice_root").text.strip()
            card_title = card.find("div", class_="GoodsCard_name").text.strip()
            card_weight = card.find("div", class_="GoodsCard_weight").text.strip()
            # print(card_url)
            print(card_title, card_price, card_weight)
